﻿using STMS.Models.UIModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STMS.WSTMSystem.UControls
{
    public partial class UCStoreBox : UserControl
    {
        public UCStoreBox()
        {
            InitializeComponent();
          
        }

        #region 控件属性

        //控件数据对象
        private UCStoreBoxModel uCStoreSource = new UCStoreBoxModel();
        public UCStoreBoxModel UCStoreSource
        {
            get { return uCStoreSource; }
            set { uCStoreSource = value;
                this.ProductCount = uCStoreSource.ProductCount;
                this.SRegionName = uCStoreSource.SRegionName;
                this.TemperRange = uCStoreSource.TemperRange;
                this.TemperState = uCStoreSource.TemperState;
                this.SRTemper = uCStoreSource.SRTemper;
                this.SRegionId = uCStoreSource.SRgionId;
                this.SId = uCStoreSource.SId;
            }
        }

        public int SId
        {
            get { return uCStoreSource.SId; }
            set
            {
                uCStoreSource.SId = value;
            }
        }

        /// <summary>
        /// 仓库分区编号
        /// </summary>
        public int SRegionId
        {
            get { return uCStoreSource.SRgionId; }
            set
            {
                uCStoreSource.SRgionId = value;
            }
        }
        /// <summary>
        /// 仓库分区名称
        /// </summary>
        public string SRegionName
        {
            get { return uCStoreSource.SRegionName; }
            set {
                uCStoreSource.SRegionName = value;
                lblSRegionName.Text = uCStoreSource.SRegionName; }
        }

        /// <summary>
        /// 设置按钮的显示
        /// </summary>
        public bool BtnSetVisible
        {
            get { return uCStoreSource.BtnSetVisible; }
            set {
                uCStoreSource.BtnSetVisible = value;
                btnSetTemper.Visible = uCStoreSource.BtnSetVisible; }
        }

        /// <summary>
        /// 设置按钮的文本
        /// </summary>
        public string BtnSetText
        {
            get { return uCStoreSource.BtnSetText; }
            set {
                uCStoreSource.BtnSetText = value;
                btnSetTemper.Text = uCStoreSource.BtnSetText; }
        }

        /// <summary>
        /// 该仓库分区的温度状态
        /// </summary>
        public int TemperState
        {
            get { return uCStoreSource.TemperState; }
            set {
                uCStoreSource.TemperState = value;
                switch (uCStoreSource.TemperState)
                {
                    case 0:
                        this.uCStoreSource.StateColor = Color.Gray;
                        this.uCStoreSource.BtnSetVisible = true;
                        this.uCStoreSource.BtnSetText = "升温";
                        break;
                    case 1:
                        this.uCStoreSource.StateColor = Color.Blue;
                        this.uCStoreSource.BtnSetVisible = false;
                        this.uCStoreSource.BtnSetText = "";
                        break;
                    case 2:
                        this.uCStoreSource.StateColor = Color.Red;
                        this.uCStoreSource.BtnSetVisible = true;
                        this.uCStoreSource.BtnSetText = "降温";
                        break;
                }
                lblStatus.BackColor = this.uCStoreSource.StateColor;
                btnSetTemper.Visible = this.uCStoreSource.BtnSetVisible;
                btnSetTemper.Text = this.uCStoreSource.BtnSetText;
            }
        }

        /// <summary>
        /// 指示灯颜色
        /// </summary>
        public Color StateColor
        {
            get { return uCStoreSource.StateColor; }
            set {
                uCStoreSource.StateColor = value;
                lblStatus.BackColor = uCStoreSource.StateColor;
            }
        }

        /// <summary>
        /// 产品数量
        /// </summary>
        public int ProductCount
        {
            get {  return  uCStoreSource.ProductCount; }
            set {
                uCStoreSource.ProductCount = value;
                lblProCount.Text = uCStoreSource.ProductCount.ToString();
            }
        }

        /// <summary>
        /// 室内温度
        /// </summary>
        public decimal SRTemper
        {
            get { return uCStoreSource.SRTemper; }
            set
            {
                uCStoreSource.SRTemper = value;
                lblSRTemper.Text = uCStoreSource.SRTemper.ToString();
            }
        }

        /// <summary>
        /// 室内温度
        /// </summary>
        public string TemperRange
        {
            get { return uCStoreSource.TemperRange; }
            set
            {
                uCStoreSource.TemperRange = value;
                lblTemperRange.Text = uCStoreSource.TemperRange.ToString()+ "℃";
            }
        }
        #endregion

        public event Action<object,UCBoxArgs> SetTemperature;//升温或降温事件
        private void UCStoreBox_Load(object sender, EventArgs e)
        {
           
        }

        private void btnSetTemper_Click(object sender, EventArgs e)
        {
            UCBoxArgs args = new UCBoxArgs(this.SRegionId, this.TemperState, this.SRTemper,this.SId);
            SetTemperature?.Invoke(sender, args);
        }
    }
}
